//
//  MMExtraVC.m
//  ZZLC
//
//  Created by 杨春至 on 2017/12/14.
//  Copyright © 2017年 ZhongZeng. All rights reserved.
//

#import "MMExtraVC.h"
#import "VTMagic.h"
#import "ZZInfoVC.h"
#import "PaperVC.h"
#import "MMRecoreVC.h"

@interface MMExtraVC ()<VTMagicViewDelegate,VTMagicViewDataSource>
{
     ZZInfoVC *_sVCm;
    PaperVC *_pVC;
    MMRecoreVC *_rVC;
}
@property (nonatomic,strong) NSArray *titleArray;

@end

@implementation MMExtraVC
- (instancetype)init{
    if ([super init]) {
        self.view.translatesAutoresizingMaskIntoConstraints = NO;
        self.magicView.sliderColor = ZZGoldColor;
        self.magicView.switchStyle = VTSwitchStyleDefault;
        self.magicView.layoutStyle = VTLayoutStyleDivide;
        self.magicView.navigationHeight = 40.f;
        self.magicView.sliderExtension = 20.0;
        self.magicView.separatorHidden = NO;
        self.magicView.scrollEnabled = YES;
        self.magicView.dataSource = self;
        self.magicView.delegate = self;
        self.magicView.needPreloading = NO;
    }
    return self;
  
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.userInteractionEnabled = YES;
    self.magicView.userInteractionEnabled = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    self.titleArray = @[@"项目信息",@"相关资料",@"投资记录"];
    [self.magicView reloadData];
}
#pragma mark ###向上滑动
- (void)scrolleToTop{
    if (self.block) {
        self.block();
    }
}
- (void)magicView:(VTMagicView *)magicView didSelectItemAtIndex:(NSUInteger)itemIndex{
    
}
- (NSArray<__kindof NSString *> *)menuTitlesForMagicView:(VTMagicView *)magicView{
    return self.titleArray;
}

- (UIButton *)magicView:(VTMagicView *)magicView menuItemAtIndex:(NSUInteger)itemIndex {
    static NSString *itemIdentifier = @"itemIdentifier";
    UIButton *menuItem = [magicView dequeueReusableItemWithIdentifier:itemIdentifier];
    if (!menuItem) {
        menuItem = [UIButton buttonWithType:UIButtonTypeCustom];
        [menuItem setTitleColor:RGBCOLOR(136, 136, 136) forState:UIControlStateNormal];
        [menuItem setTitleColor: ZZGoldColor forState:UIControlStateSelected];//鲜花常识的颜色
        menuItem.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:15.f];
        menuItem.width = KWidth/3;
    }
    return menuItem;
}

- (UIViewController *)magicView:(VTMagicView *)magicView viewControllerAtPage:(NSUInteger)pageIndex{
    __weak MMExtraVC *weakSelf = self;
    if (pageIndex == 0) {
        if (!_sVCm) {
            _sVCm = [[ZZInfoVC alloc]init];
            _sVCm.block = ^{
                [weakSelf scrolleToTop];
            };
        }
        return _sVCm;
    } if (pageIndex == 1){
        if (!_pVC) {
            _pVC = [[PaperVC alloc]init];
            _pVC.block = ^{
                [weakSelf scrolleToTop];
            };
        }
   
//        _pVC.dataSource = self.imArray;
        return _pVC;
    }else{
       if (!_rVC) {
           _rVC = [[MMRecoreVC alloc]init];
           _rVC.block = ^{
               [weakSelf scrolleToTop];
           };
       }
        return _rVC;
    }

//    sVC.view.backgroundColor = [UIColor qmui_randomColor];
//    return sVC;
}
- (void)setInfoArray:(NSMutableArray *)infoArray{
    _infoArray = infoArray;
    _sVCm.dataArray = infoArray;
}
- (void)setImArray:(NSMutableArray *)imArray{
    _imArray = imArray;
    _pVC.dataSource = imArray;
}
- (void)setProductId:(NSString *)productId{
    if (!_rVC) {
        _rVC = [[MMRecoreVC alloc]init];
        _rVC.block = ^{
            [self scrolleToTop];
        };
    }
    _productId = productId;
    _rVC.pid = _productId;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
